package com.itheima.controller;

import com.itheima.pojo.Customer;
import com.itheima.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class RegController {
    @Autowired
    private CustomerService customerService;

    @GetMapping("/reg")
    public String reg() {
        return "register";
    }

    @PostMapping("/doReg")
    public String doReg(Customer customer) {
//        System.out.println(customer);
        //调用服务层的注册功能
        customerService.register(customer);
        return"redirect:/";    }

    @PostMapping("/customer")
    public String addCus(Customer customer) {
        System.out.println(customer);
        return "login";
    }


//    @ResponseBody
//    @PostMapping("/isExistUsername")
//    public String isExistUsername(@RequestParam String username) {
//        if (username.equals("aaa")) {
//            return "1";
//        } else {
//            return "0";
//        }
//
//    }
//    @ResponseBody
//    @PostMapping("/isExistTel")
//    public String isExistTel(@RequestParam String tel) {
//        if (tel.equals("123456")) {
//            return "1";
//        } else {
//            return "0";
//        }
//
//    }


    //判断账号是否重复（POST方式异步请求）
    @ResponseBody
    @PostMapping("/customer/usernameIsExist")
    public int usernameIsExist(String username){
        return customerService.usernameIsExist(username);
    }

    @ResponseBody
    @PostMapping("/customer/telIsExist")
    public int telIsExist(String tel){
        return customerService.telIsExist(tel);
    }

    @ResponseBody
    @PostMapping("/customer/passIsExist")
    public int passIsExist(String pass){
        return customerService.passIsExist(pass);
    }
}